package com.example.demo.mapper;

import com.example.demo.pojo.dto.OrderPageDTO;
import com.example.demo.pojo.entity.Order;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper {

    void insert(Order order);

    List<Order> list(Order order);

    @Select("select * from `order` where id=#{id}")
    Order getById(Long id);

    @Select("select * from `order` where number=#{number} and user_id=#{userId}")
    Order getByNumberAndUserId(String number, Long userId);

    void update(Order order);


    Page<Order> pageQuery(OrderPageDTO orderPageDTO);

    @Select("Select sum(amount) as totalSales from `order` where status!=5")
    Double getTotalSales();

    @Select("select count(id) from `order` where status=4")
    Integer getTotalPaid();

    @Select("select count(id) from `order` where DATE (order_time)=curdate()")
    Integer getDayOrders();

    @Select("select count(id) from `order` where DATE (order_time)=curdate() and status!=5")
    Integer getDayValidOrders();

    @Select("select sum(amount) from `order` where DATE (order_time)=curdate() and status!=5")
    Double getDaySales();

    @Select("select count(id) from `order` where DATE (order_time) >=DATE_ADD(CURDATE(), INTERVAL 1-DAYOFMONTH(CURDATE()) DAY) and DATE (order_time) <LAST_DAY(CURDATE())")
    Integer getMonthOrders();

    @Select("select count(id) from `order` where DATE (order_time) >=DATE_ADD(CURDATE(), INTERVAL 1-DAYOFMONTH(CURDATE()) DAY) and DATE (order_time) <LAST_DAY(CURDATE()) and status!=5")
    Integer getMonthValidOrders();

    @Select("select sum(amount) from `order` where DATE (order_time) >=DATE_ADD(CURDATE(), INTERVAL 1-DAYOFMONTH(CURDATE()) DAY) and DATE (order_time) <LAST_DAY(CURDATE()) and status!=5")
    Double getMonthSales();
}
